#include "Point.h"
#include "MyScreen.h"

MyScreen::MyScreen()
{
	for (int i=0; i < (MAX_SCREEN_X-1); i++)
		for (int j=0; j < (MAX_SCREEN_Y-1); j++)
			m_screen[i][j] = ' ';
}

bool MyScreen::legal(int x , int y) const
{
	return (x < MAX_SCREEN_X && y < MAX_SCREEN_Y && x >= MIN_SCREEN_X && y >= MIN_SCREEN_Y);
}

bool MyScreen::set(int x, int y, char ch)
{
	if (legal(x,y))
	{
		m_screen[x][y] = ch;
		return true;
	}
	return false;
}

void MyScreen::print() const
{
	for (int i=0; i < MAX_SCREEN_X-1; i++)
		for (int j=0; j < MAX_SCREEN_Y-1; j++)
		{
			if (this->isSet(i,j))
			{
				gotoxy( i, j);
				cout << m_screen[i][j] ;
			}
		}
}

void MyScreen::Diff(const MyScreen * scr) const
{
	for (int i=0; i < MAX_SCREEN_X -1; i++)
		for (int j=0; j < MAX_SCREEN_Y -1; j++)
		{
			if (scr->getChar(i,j) ^ m_screen[i][j])
			{
				gotoxy( i, j);
				cout << scr->getChar(i,j);
			}
		}
}

void MyScreen::clearScreen()
{
	for (int i=0; i < (MAX_SCREEN_X-1); i++)
		for (int j=0; j < (MAX_SCREEN_Y-1); j++)
			m_screen[i][j] = ' ';
}